package cn.hr.service.impl;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import cn.hr.dao.mapper.PayrollDetailMapper;
import cn.hr.dao.mapper.SalProStanMapper;
import com.github.pagehelper.PageInfo;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import cn.hr.dao.mapper.SalaryProMapper;
import cn.hr.pojo.SalaryPro;
import cn.hr.service.SalaryProService;

/**
 * 薪酬项目服务接口实现类
 *
 * @author MO
 */
@CacheConfig(cacheNames = "salaryPro")
@Scope("prototype")
@Service("salaryProService")
public class SalaryProServiceImpl implements SalaryProService {
    @Resource
    private SalaryProMapper salaryProMapper;
    @Resource
    private SalProStanMapper salProStanMapper;
    @Resource
    private PayrollDetailMapper payrollDetailMapper;
    @Override
    public boolean insert(SalaryPro t) throws Exception {
        return salaryProMapper.insert(t) > 0;
    }

    @Override
    public boolean update(SalaryPro t) throws Exception {
        return salaryProMapper.update(t) > 0;
    }

    @Override
    public boolean delete(Integer id) throws Exception {
        return false;
    }
    @CacheEvict(allEntries = true)
    public String deleteById(Integer id)throws SQLException{
        HashMap<String,Object> map = new HashMap<>();
        String result = "false";
        map.put("salP",id);
        if (salProStanMapper.findCountByCondition(map)==0&&payrollDetailMapper.findCountByCondition(map)==0){
            if ( salaryProMapper.delete(id) > 0){
                result = "true";
            }
        }else{
            result = "isCount";
        }
        return result;
    }


    @Override
    public SalaryPro get(Integer id) throws Exception {
        return salaryProMapper.get(id);
    }

    @Override
    public PageInfo<Map> findListByCondition(Map m, int pageNo) throws Exception {
        List<Map> list = salaryProMapper.findListByCondition(m);
        return new PageInfo<>(list);
    }

    @Override
    public Long findCountByCondition(Map m) throws Exception {
        return null;
    }

    public Integer findMin()throws Exception{
        return salaryProMapper.findMaxId();
    }
}
